import {
  AlignmentType,
  Document,
  HeadingLevel,
  Paragraph,
  TextRun,
} from "docx";

export class DocumentCreator {
  // tslint:disable-next-line: typedef
  public create(props: any): Document {
    const { time, fName, fdata, ulist } = props;
    const document = new Document({
      sections: [
        {
          children: [
            new Paragraph({
              text: "四川知周科技有限责任公司",
              heading: HeadingLevel.HEADING_3,
              alignment: AlignmentType.CENTER,
              thematicBreak: true,
            }),
            new Paragraph({
              text: "会议纪要",
              heading: HeadingLevel.HEADING_1,
              alignment: AlignmentType.CENTER,
              thematicBreak: true,
            }),
            new Paragraph({
              text: time,
              alignment: AlignmentType.CENTER,
              thematicBreak: true,
            }),
            new Paragraph({
              text: `${fName}周汇报`,
              heading: HeadingLevel.HEADING_2,
              alignment: AlignmentType.CENTER,
              thematicBreak: true,
            }),
            new Paragraph({
              text: ``,
            }),
            new Paragraph({
              text: `地    点: 知周科技会议室`,
            }),
            new Paragraph({
              text: ``,
            }),
            new Paragraph({
              text: `主    持：陈良杰`,
            }),
            new Paragraph({
              text: ``,
            }),
            new Paragraph({
              text: `参会人员：刘智、陈良杰、马骏、李杰、陈根、王书波、王晖、纪垟震、帅杨、 杨欢、王鑫、余卓凡、张仕君、梁涵絮 共计14人`,
            }),
            new Paragraph({
              text: ``,
            }),
            new Paragraph({
              text: `记    录：杨欢`,
            }),
            new Paragraph({
              text: ``,
            }),
            new Paragraph({
              text: `会议主题：`,
            }),
            new Paragraph({
              text: `为确保本部门项目开发进度按需求方要求时间内准时、有效的完成，刘智经理组织每周召开项目进度汇报会议；会上详细梳理了每个成员的工作内容、工作进度、未来工作安排以及遇到的问题及时探讨并给出解决方案和后期解决问题的跟进；并对下阶段的工作安排进行部署。`,
            }),
            new Paragraph({
              text: ``,
            }),
            new Paragraph({
              text: `会议内容：`,
            }),
            new Paragraph({
              text: `xxxxxx`,
            }),
            new Paragraph({
              text: `xxxxxx`,
            }),
            new Paragraph({
              text: `xxxxxx`,
            }),
            new Paragraph({
              text: `接下来针对${fName}项目的进度、技术难点和解决方案进行了汇报和深入的讨论。工作内容及安排如下：`,
            }),
            new Paragraph({
              text: ``,
            }),
            ...this.createSubHeading(fdata, ulist),
            new Paragraph({
              text: ``,
            }),
            new Paragraph({
              text: ``,
            }),
            new Paragraph({
              text: `知周科技软件部`,
              alignment: AlignmentType.RIGHT,
            }),
            new Paragraph({
              text: `时间：${time}`,
              alignment: AlignmentType.RIGHT,
            }),
          ],
        },
      ],
    });

    return document;
  }

  public createSubHeading(fdata: any, ulist: any): Paragraph[] {
    return fdata.map((item: any, index: any) => {
      const i = ulist.findIndex((e: any) => e.value === item.userid);
      let str = "";
      if (i != -1) {
        str = ulist[i].label;
      }
      let notes = "";
      if (item.notes) {
        JSON.parse(item.notes).forEach((n: any) => {
          notes += `${n.time}：${n.info}`;
        });
      }
      return new Paragraph({
        text: `${index} ${str} ${item.startTime} ${item.name}`,
        children: [
          new TextRun({
            text: notes.trim().length === 0 ? "" : `,备注：${notes}`,
          }),
        ],
      });
    });
  }
}
